package com.fa.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DatabaseMetadataMapper {

    // 查询数据库中的所有表名
    @Select("SELECT table_name FROM information_schema.tables WHERE table_schema = #{databaseName}")
    List<String> getAllTables(String databaseName);

    // 查询指定表的所有列信息
    @Select("SELECT column_name AS name, data_type AS type, column_comment AS remarks, " +
            "(case when (is_nullable = 'no' and column_key != 'PRI') then '1' else '0' end) as is_required, " +
            "(case when column_key = 'PRI' then '1' else '0' end) as is_pk ," +
            "(case when extra = 'auto_increment' then '1' else '0' end) as is_increment " +
            "FROM information_schema.columns " +
            "WHERE table_schema = #{databaseName} AND table_name = #{tableName}")
    List<Map<String, String>> getTableMetadata(String databaseName, String tableName);
}
